package com.iexbuy.ihg.ui.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import com.iexbuy.ihg.App;
import com.iexbuy.ihg.R;
import com.iexbuy.ihg.net.ServiceHelper;
import com.iexbuy.ihg.utils.StringUtil;
import com.iexbuy.ihg.utils.ToastUtils;
import com.jingchen.pulltorefresh.PullToRefreshLayout;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.umeng.socialize.bean.SHARE_MEDIA;

import java.util.HashMap;

public class WeDeShareFragment extends BaseFragment {

	private static WeDeShareFragment homeFragmentInstent;

	@ViewInject(R.id.msgListLayout)
	private PullToRefreshLayout msgListRefreshLayout;

	//邀请你的
	@ViewInject(R.id.shareMobileInviteYouEdt)
	private EditText shareMobileInviteYouEdt;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		homeFragmentInstent = this;
	}

	@Override
	protected View _onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_wede_share, container, false);
		ViewUtils.inject(this, rootView);
		initView(rootView);
		return rootView;
	}

	private void initView(View rootView) {
		mBaseActivity.setTitle(getResources().getString(R.string.we_de_share));
		mBaseActivity.setTitleLayoutVisibility(true);
		mBaseActivity.setHomeActivity(false);


	}

	/**
	 * 邀请你的小伙伴号码 按键提交
	 * @param view
	 */
	@OnClick(R.id.submitShareInviteYouBtn)
	public void submitShareInviteYouBtnClick(View view) {
		if (StringUtil.isEmpty(shareMobileInviteYouEdt.getText().toString())) {
			ToastUtils.toast(mBaseActivity, "请填写邀请人的手机号码");
			return;
		}
		HashMap<String, String> paramMap = new HashMap<String, String>();
		paramMap.put("userId", App.sPreferences.getUserId());
		paramMap.put("invitorMobile", shareMobileInviteYouEdt.getText().toString());
		ServiceHelper.send(mBaseActivity, ServiceHelper.SUBIT_INVITOR_MOBILE, paramMap,
				new RequestCallBack<String>() {
					@Override
					public void onStart() {
						mBaseActivity.showDialog("提交中...");
					}

					@Override
					public void onCancelled() {
						mBaseActivity.closeDialog();
					}

					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {
						mBaseActivity.closeDialog();
						ToastUtils.toast(mBaseActivity, "提交成功");
					}

					@Override
					public void onFailure(HttpException error, String msg) {
						mBaseActivity.closeDialog();
						ToastUtils.toast(mBaseActivity, msg);
					}
				});
	}

	/**
	 * 微信分享
	 * @param view
	 */
	@OnClick(R.id.shareWeixinBtn)
	public void shareWeixinBtnClick(View view) {
		App.umSocialService.getConfig().setPlatforms(SHARE_MEDIA.WEIXIN);
		App.umSocialService.openShare(mBaseActivity, false);
	}

	/**
	 * 朋友圈分享
	 * @param view
	 */
	@OnClick(R.id.shareCircleBtn)
	public void shareCircleBtnClick(View view) {
		App.umSocialService.getConfig().setPlatforms( SHARE_MEDIA.WEIXIN_CIRCLE);
		App.umSocialService.openShare(mBaseActivity, false);
	}

	/**
	 * 分享按钮
	 * @param view
	 */
	/*@OnClick(R.id.shareBtn)
	public void shareBtnClick(View view) {
		App.umSocialService.getConfig().setPlatforms(SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE);
		App.umSocialService.openShare(mBaseActivity, false);
	}*/


	/**
	 * @return the homeFragmentInstent
	 */
	public static WeDeShareFragment getHomeFragmentInstent() {
		return homeFragmentInstent;
	}

}
